package com.lyc.service.impl;

import com.lyc.service.GaodeMapService;
import com.lyc.utils.GaodeMapUtil;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class GaodeMapServiceImpl implements GaodeMapService {

    /**
     * 地理编码：将地址转换为经纬度
     *
     * @param address 地址
     * @return 经纬度信息
     */
    @Override
    public String geocode(String address) throws Exception {
        Map<String, String> params = new HashMap<>();
        params.put("address", address);
        return GaodeMapUtil.sendGetRequest("/geocode/geo", params);
    }

    /**
     * 逆地理编码：将经纬度转换为地址
     *
     * @param location 经纬度 (格式: 经度,纬度)
     * @return 地址信息
     */
    @Override
    public String regeocode(String location) throws Exception {
        Map<String, String> params = new HashMap<>();
        params.put("location", location);
        return GaodeMapUtil.sendGetRequest("/geocode/regeo", params);
    }

    /**
     * 路径规划：计算两点间的路线
     *
     * @param origin      起点坐标 (格式: 经度,纬度)
     * @param destination 终点坐标 (格式: 经度,纬度)
     * @return 路线信息
     */
    @Override
    public String calculateRoute(String origin, String destination) throws Exception {
        Map<String, String> params = new HashMap<>();
        params.put("origin", origin);
        params.put("destination", destination);
        return GaodeMapUtil.sendGetRequest("/direction/driving", params);
    }

    /**
     * 周边搜索：搜索指定坐标附近的POI
     *
     * @param location 中心点坐标 (格式: 经度,纬度)
     * @param keywords 搜索关键词
     * @return POI信息
     */
    @Override
    public String searchNearby(String location, String keywords) throws Exception {
        Map<String, String> params = new HashMap<>();
        params.put("location", location);
        params.put("keywords", keywords);
        return GaodeMapUtil.sendGetRequest("/place/around", params);
    }
}